package com.shop.cloud.service.hongfu.impl;

import com.shop.cloud.domain.hongfu.RebateConfig;
import com.shop.cloud.domain.hongfu.User;
import com.shop.cloud.service.hongfu.IRebateConfigService;
import com.shop.cloud.service.hongfu.IUserService;
import com.shop.cloud.dao.hongfu.RebateConfigDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.shop.cloud.common.mybatis.BaseService;
import com.shop.cloud.common.mybatis.MybatisDao;

/**
 * 
 */
@Service("rebateConfigService")
public class RebateConfigService extends BaseService<RebateConfig> implements IRebateConfigService{
    
    @Autowired
	private RebateConfigDao rebateConfigDao;
    
    @Autowired
    private IUserService userService;

	@Override
	public MybatisDao<RebateConfig> getEntityDao() {
		return rebateConfigDao;
	}

	@Override
	public String handleUserRebate(Long userId) {
		
		RebateConfig rebateConfig = this.get(new Long(1)); 
		User insUser = userService.get(userId);
		
		float rebateLimit = rebateConfig.getRebateLimit();
		float balance = insUser.getBalance();
		
		if(balance >= rebateLimit){
			return 0+","+rebateLimit;
		}else{
			return 1+","+rebateLimit;
		}
	}
    
}